imports('../../../style/voucher/record');

var template = require('template');

template.method('number', function(val){
    if(!val){
        return ''
    }
    return val.replace(/[-.]/g, '')
})

return {
    left:renders({
        <span class="e-mt10 f-cdarkgray f-fl">
            <i class="iconfont e-mr10 f-cp">&#xe64a;</i>
            请按回车键或者Tab，能快速选择单元格哦！
        </span>
    }),
    right:renders({
        <%if !isSuperlayer??%>
        <button class="ui-button ui-button-fixed f-fl e-mr10">更多凭证</button>
        <%/if%>
        <button class="ui-button ui-button-normal f-fl e-mr1<%if !upVoucherId?? || !upVoucherId%> ui-button-disabled<%/if%> j-prev">
            <i class="iconfont">&#xe613;</i>
        </button>
        <button class="ui-button ui-button-normal f-fl<%if !nextVoucherId?? || !nextVoucherId%> ui-button-disabled<%/if%> j-next">
            <i class="iconfont">&#xe610;</i>
        </button>
    }),
    body:renders({
        <div class="m-voucher-box g-w1200">
            <%include 'head'%>
            <form class="m-voucher e-mt10">
                <div class="voucher-head f-clearfix e-mlr">
                    <div class="ui-item f-fl">
                        <span class="ui-item-label f-lh35">记字第：</span>
                        <input type="text" name="vCode" value="<%vCode??%>" class="ui-input ui-input-large ui-input-short e-pl0 f-tac" readonly>
                        <b class="f-lh35 e-ml5">号</b>
                    </div>
                    <div class="ui-item f-fl f-pa">
                        <span class="ui-item-label f-lh35">日期：</span>
                        <input type="text" name="vDate" value="<%vDate??%>" class="ui-input ui-input-large ui-input-date" readonly>
                    </div>
                    <div class="ui-item f-fr">
                        <span class="ui-item-label f-lh35">附单据：</span>
                        <input type="text" name="vAffix" value="<%vAffix??%>" class="ui-input ui-input-large ui-input-short e-pl0 f-tac" data-integer="9" data-decimal="0" autocomplete="off">
                        <b class="f-lh35 e-ml5">张</b>
                    </div>
                </div>
                <div class="voucher-body e-mt15<%if isAccount?? && isAccount%> show-number<%/if%><%if isCurrency?? && isCurrency%> show-currency<%/if%>">
                    <%include 'tableHead'%>
                    <%include 'tableBody'%>
                    <%include 'tableFoot'%>
                </div>
                <div class="voucher-foot e-mt15 f-clearfix e-mlr">
                    <span class="f-fl">
                        <span class="f-fl e-mr50">制单人：邓本</span>
                        <span class="f-fl">审核人：邓本</span>
                    </span>
                    <div class="f-fr voucher-button">
                        <%include 'button'%>
                    </div>
                </div>
            </form>
        </div>
    }),
    tableHead:renders({
        <table class="f-tlf f-tac e-mlr">
            <thead class="voucher-thead">
                <tr>
                    <td class="col-summary">
                        <em class="f-fwb">摘要</em>
                    </td>
                    <td class="col-subject">
                        <em class="f-fwb">会计科目</em>
                    </td>
                    <td class="col-number">
                        <em class="f-fwb">数量</em>
                    </td>
                    <td class="col-currency">
                        <em class="f-fwb">外币</em>
                    </td>
                    <td class="col-debit">
                        <div>
                            <em class="f-fwb">借方金额</em>
                        </div>
                        <%include 'cn_title'%>
                    </td>
                    <td class="col-credit">
                        <div>
                            <em class="f-fwb">贷方金额</em>
                        </div>
                        <%include 'cn_title'%>
                    </td>
                </tr>
            </thead>
        </table>
    }),
    tableBody:renders({
        <div class="voucher-content e-mt-1">
            <table class="f-tlf">
                <tbody class="voucher-tbody">
                    <%each vouchers voucher%>
                    <%include 'row'%>
                    <%/each%>
                </tbody>
            </table>
        </div>
    }),
    tableFoot:renders({
        <div class="e-mt-1 e-mlr e-pr1">
            <table class="g-w100">
                <tbody class="voucher-tfoot">
                    <%include 'total'%>
                </tbody>
            </table>
        </div>
    }),
    voucher:renders({
        <%if !voucher??%>
            <%var voucher = {}%>
        <%/if%>
    }),
    row:renders({
        <%include 'voucher'%>
        <tr class="table-row<%if voucher.isCurrency%> row-currency<%elseif voucher.isAccount%> row-account<%/if%>">
            <td class="col-button">
                <span class="cell-button">
                    <i class="iconfont f-cblue j-addrow e-mauto" title="插入行">&#xe64c;</i>
                    <i class="iconfont f-cblue j-delrow e-mauto e-mt5" title="删除行">&#xe64b;</i>
                </span>
            </td>
            <td class="col-summary f-wbba">
                <div class="cell-edit">
                    <div class="cell-edit-text">
                        <span class="cell-text"><%voucher.summary??%></span>
                    </div>
                    <div class="cell-edit-inner">
                        <div class="cell-edit-input">
                            <textarea class="cell-input cell-input-full" name="summary"><%voucher.summary??%></textarea>
                        </div>
                    </div>
                </div>
            </td>
            <td class="col-subject f-wbba">
                <div class="cell-edit">
                    <div class="cell-edit-text">
                        <%include 'subject_ext'%>
                        <span class="cell-text"><%voucher.subject??%></span>
                    </div>
                    <div class="cell-edit-inner">
                        <%include 'subject_ext'%>
                        <div class="cell-edit-input">
                            <textarea class="cell-input cell-input-full" name="subject"><%voucher.subject??%></textarea>
                        </div>
                    </div>
                </div>
            </td>
            <td class="col-number">
                <%include 'number'%>
            </td>
            <td class="col-currency">
                <%include 'currency'%>
            </td>
            <td class="col-debit lines">
                <div class="cell-edit">
                    <div class="cell-edit-text">
                        <span class="cell-text<%if voucher.debitAmt<0%> f-cred<%/if%>"><%number | voucher.debitAmt%></span>
                    </div>
                    <div class="cell-edit-inner">
                        <div class="cell-edit-input">
                            <input class="cell-input cell-input-full input-money" 
                                   data-integer="9" data-minus="true" data-convert="true" value="<%voucher.debitAmt??%>" name="debitAmt" autocomplete="off">
                        </div>
                    </div>
                </div>
            </td>
            <td class="col-credit lines">
                <div class="cell-edit">
                    <div class="cell-edit-text">
                        <span class="cell-text<%if voucher.creditAmt<0%> f-cred<%/if%>"><%number | voucher.creditAmt%></span>
                    </div>
                    <div class="cell-edit-inner">
                        <div class="cell-edit-input">
                            <input class="cell-input cell-input-full input-money" 
                                   data-integer="9" data-minus="true" value="<%voucher.creditAmt??%>" data-convert="true" name="creditAmt" autocomplete="off">
                        </div>
                    </div>
                </div>
            </td>
        </tr>
    }),
    subject_ext:renders({
        <%include 'voucher'%>
        <span class="edit-subject"><a class="f-cblue j-subject">科目</a></span>
        <span class="edit-balance"><%if voucher.subject??%><%include 'balance'%><%/if%></span>
    }),
    balance:renders({
        余额：<em class="f-cp j-balance">0.00</em>
    }),
    cn_title:renders({
        <div class="lines">
            <%each '亿千百十万千百十元角分'.split('')%>
            <b class="f-fwb"><%$value%></b>
            <%/each%>
        </div>
    }),
    number:renders({
        <%include 'voucher'%>
        <%if voucher.isAccount%>
        <div class="cell-edit">
            <div class="cell-edit-inner">
                <div class="cell-edit-input f-lh20">
                    <p>单位 <%voucher.name??%></p>
                    <p>数量 <input type="text" 
                                   class="cell-input input-adjust" name="amount" data-minus="true" data-integer="9" data-decimal="4" data-convert="true"
                                   data-number="0" value="<%voucher.amount??%>" autocomplete="off"></p>
                    <p>单价 <input type="text" 
                                  class="cell-input input-adjust<%if !voucher.isCurrency%> s-rdy<%/if%>" 
                                  name="price" data-integer="9" data-decimal="4" data-number="0" value="<%voucher.price??%>"
                                  <%if !voucher.isCurrency%> readonly<%/if%> autocomplete="off"></p>
                </div>
            </div>
        </div>
        <%/if%>
    }),
    currency:renders({
        <%include 'voucher'%>
        <%if voucher.isCurrency%>
        <div class="cell-edit">
            <div class="cell-edit-inner">
                <div class="cell-edit-input f-lh20">
                    <p><%voucher.symbolname??%> <%voucher.symbol??%><input type="hidden" name="symbol" value="<%voucher.symbol??%>"></p>
                    <p>原币 <input type="text" class="cell-input input-adjust" 
                                   name="money" data-minus="true" data-integer="9" data-number="0" data-convert="true" value="<%voucher.money??%>" autocomplete="off"></p>
                    <p>汇率 <input type="text" class="cell-input input-adjust" 
                                   name="rate" data-integer="9" data-decimal="4" data-number="0" value="<%voucher.rate??%>" autocomplete="off"></p>
                </div>
            </div>
        </div>
        <%/if%>
    }),
    total:renders({
        <tr>
            <td class="f-fwb e-pl10">合计：<%total_cn??%></td>
            <%if total_debit?? && total_debit%>
            <td class="col-debit lines">
                <div class="cell-edit-text">
                    <span class="cell-text<%if total_debit<0%> f-cred<%/if%>"><%number | total_debit%></span>
                </div>
            </td>
            <%else%>
            <td class="col-debit lines"></td>
            <%/if%>
            <%if total_credit?? && total_credit%>
            <td class="col-credit lines">
                <div class="cell-edit-text">
                    <span class="cell-text<%if total_credit<0%> f-cred<%/if%>"><%number | total_credit%></span>
                </div>
            </td>
            <%else%>
            <td class="col-credit lines"></td>
            <%/if%>
        </tr>
    }),
    button:renders({
        <button type="button" class="ui-button ui-button-fixed<%if !allowSave??%> ui-button-disabled<%/if%> f-fl e-ml10 j-saveadd">保存并新增</button>
        <button type="button" class="ui-button ui-button-fixed ui-button-normal<%if !allowSave??%> ui-button-disabled<%/if%> f-fl e-ml10 j-save">保存</button>
    })
}